package goleetcode

import "sort"

func maxNumOfMarkedIndices(nums []int) int {
	sort.Ints(nums)
	n := len(nums)
	l, r := 0, n / 2

	check := func(m int) bool {
		for i := 0; i < m; i++ {
			if nums[i] * 2 > nums[n - m + i] {
				return false
			}
		}
		return true
	}

	for l < r {
		m := (l + r + 1) >> 1
		if check(m) {
			l = m
		} else {
			r = m - 1
		}
	}

	return l * 2
}
